<?php
namespace app\wechat\controller;

use app\common\controller\AdminBaseController;
use app\wechat\model\WechatReply as ReplyModel;
/**
 * 自动回复
 */
class ReplyController extends AdminBaseController {

	protected $reply_model;

	protected function _initialize() {
		parent::_initialize();
		$this -> reply_model = new ReplyModel();
	}

	/**
	 * 列表
	 * @return mixed
	 */
	public function index() {
		$list = $this -> reply_model -> where('mid', 0) -> paginate(15);
		$this -> assign('list', $list);
		return $this -> fetch();
	}

/**
	 * 添加
	 * @param string $pid
	 * @return mixed
	 */
	public function add() {
		$store_id = session('storeInfo')['id'];		
    	if(request()->isAjax()){   		
            $param = input('post.');             
			$param['mid'] =  '0';  
         	if ($this->reply_model->allowField(true)->save($param) !== false) {
                    $this->success('保存成功', url('reply/index'));
            } else {
                $this->error('保存失败');
            }
        }       
		return $this->fetch();
	}

    /**
     * [edit 编辑]
     * @return [type] [description]
     * @author [longx]
     */
    public function update($id)
    {
        if(request()->isAjax()){
            $param = input('post.');         
         	if ($this->reply_model->allowField(true)->save($param,$id) !== false) {
                    $this->success('修改成功', url('reply/index'));
            } else {
                $this->error('修改失败');
            }
        }
        $id = input('param.id');
        $this->assign('ad',$this->reply_model->find($id));
        return $this->fetch();
    }

	/**
	 * 删除
	 * @param $id
	 */
	public function delete($id) {
		if ($this -> reply_model -> destroy($id)) {
			$this -> success('删除成功');
		} else {
			$this -> error('删除失败');
		}
	}

}
